package gogogo.liwushuo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import gogogo.liwushuo.R;
import gogogo.liwushuo.bean.SingleProductBean;

/**
 * Created by cong on 2016/7/20.
 */
public class SpRightRvItemAdapter extends RecyclerView.Adapter<SpRightRvItemAdapter.MyHolder> {
    private Context mContext;
    private List<SingleProductBean.DataBean.CategoriesBean.SubcategoriesBean> mList;

    public SpRightRvItemAdapter(Context context, List<SingleProductBean.DataBean.CategoriesBean.SubcategoriesBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_sp_right, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        Picasso.with(mContext).load(mList.get(position).getIcon_url()).into(holder.iv);
        holder.tv.setText(mList.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv;
        public MyHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.item_sp_right_iv);
            tv = (TextView) itemView.findViewById(R.id.item_sp_right_tv);
        }
    }
}
